<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>源辰-添加新闻</title>
<link rel="shortcut icon" href="../../images/copylogo.png"
	type="image/x-icon" />
<link rel="stylesheet" href="../css/common.css">
<link rel="stylesheet" href="../css/main.css">
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/showpic.js"></script>
<script type="text/javascript" src="../../js/ajaxfileupload.js"></script>
<script src="../../ckeditor/ckeditor.js"></script>
</head>
<body>
	<div id="forms" class="mt10">
		<div class="box">
			<div class="box_border">
				<div class="box_top">
					<b class="pl15">添加博文</b>
				</div>
				<div class="box_center">
					<form action="" class="jqtransform" id="addBlog">
						<table class="form_table pt15 pb15" width="100%" border="0"
							cellpadding="0" cellspacing="0">
							<tr>
								<td class="td_right">博文类型：</td>
								<td><select class="select" name="tid" id="tid">
										<option value="">--请选择--</option>
								</select></td>
								<td class="td_right">博文标题：</td>
								<td><input type="text" id="title" name="title"
									class="input-text lh30" size="40" placeholder="请输入新闻标题">
								</td>
							</tr>
							<tr>
								<td class="td_right">博文内容：</td>
								<td colspan="3"><textarea name="editor1" id="editor1"
										rows="10" cols="80"></textarea></td>
							</tr>
							<tr>
								<td colspan="4" align="center"><input type="button"
									name="button" class="btn btn82 btn_save2"
									onclick="addBlogInfo()" value="添加"> <input type="reset"
									name="button" class="btn btn82 btn_res" value="重置"></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	CKEDITOR.replace( 'editor1' );
	$(function () {
		$.get("../../type",{op:"findAll"}, result =>{
			var str="";
			$.each(result,function(index,item){
				str +="<option value='"+ item.tid +"'>"+ item.tname +"</option>";
			})
			$("#tid").append($(str));
		},"json");
	})
	
	
	function addBlogInfo(){
		var tid=$.trim($("#tid").val());
		var title=$.trim($("#title").val());
		var content=CKEDITOR.instances.editor1.getData();//获取文本编辑器中的内容
		
		if(tid==""){
			alert("请选择博文类型...");
			return;
		}
		if(title==""){
			alert("博文标题不能为空..");
			return;
		}
		if(content==""){
			alert("博文内容不能为空...");
			return;
		}
		
		$.post("../../blog",{op:"add",title:title,tid:tid,content:content}, result =>{
			result=parseInt($.trim(result));
			if(result > 0){
				alert("添加博文成功...");
				$("#addBlog")[0].reset();
				CKEDITOR.instances.editor1.setData("");
			}else {
				alert("添加博文失败...");
			}
		},"text");
	}
</script>
</body>
</html>